import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;


public class FisioSoft {
	

	private JFrame frmFisiosoft;
	private final JPanel panel = new JPanel();
	private final JLabel lblUsuario = new JLabel("Usuario: ");
	private final JLabel lblPassword = new JLabel("Password: ");
	private final JTextField textField = new JTextField();
	private final JLabel lblSeleccioneElIdioma = new JLabel("Seleccione el idioma que desee: ");
	private final JComboBox comboBox = new JComboBox();
	private final JButton btnNewButton = new JButton("Confirmar\n");
	private final JPasswordField passwordField = new JPasswordField();
	
	private final Sanitario s1=new Sanitario("Juan","Ortiz","123");
	private final Sanitario s2=new Sanitario("Pepe","Ortiz","111");
	
	private final static  ArrayList<Sanitario> lsan=new ArrayList<Sanitario>();


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FisioSoft window = new FisioSoft();
					window.frmFisiosoft.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public FisioSoft() {
		
		initialize();
		
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		lsan.add(s1);
		lsan.add(s2);
		frmFisiosoft = new JFrame();
		frmFisiosoft.setResizable(false);
		frmFisiosoft.setName("Autentificacion");
		frmFisiosoft.setTitle("FisioSoft");
		frmFisiosoft.setBounds(100, 100, 450, 300);
		frmFisiosoft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmFisiosoft.getContentPane().setLayout(new BorderLayout(3, 2));
		{
			frmFisiosoft.getContentPane().add(panel, BorderLayout.CENTER);
		}
		panel.setLayout(null);
		{
			lblUsuario.setBounds(58, 40, 56, 16);
			panel.add(lblUsuario);
		}
		textField.setBounds(152, 35, 233, 27);
		textField.setColumns(10);
		{
			panel.add(textField);
		}
		{
			passwordField.setBounds(152, 83, 233, 27);
			panel.add(passwordField);
		}
		frmFisiosoft.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{frmFisiosoft.getContentPane(), panel, lblUsuario, textField, lblPassword, lblSeleccioneElIdioma, comboBox, btnNewButton, passwordField}));
		{
			lblPassword.setBounds(58, 89, 67, 16);
			panel.add(lblPassword);
		}
		{
			lblSeleccioneElIdioma.setBounds(58, 140, 203, 16);
			panel.add(lblSeleccioneElIdioma);
		}
		{
			comboBox.setBounds(132, 181, 105, 27);
			comboBox.setModel(new DefaultComboBoxModel(new String[] {"Español", "Inglés"}));
			panel.add(comboBox);
		}
		btnNewButton.addActionListener(new BtnNewButtonActionListener());
		btnNewButton.setBounds(314, 220, 117, 40);
		panel.add(btnNewButton);
		panel.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{textField, passwordField, comboBox, btnNewButton, lblUsuario, lblPassword, lblSeleccioneElIdioma}));
	}
	private class BtnNewButtonActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			Principal p =new Principal();
			boolean acceso=false;
			
			for (int i=0;i<lsan.size();i++){
				if(lsan.get(i).getNombre().equals(textField.getText().toString())&& Arrays.equals(lsan.get(i).getPass().toCharArray(),passwordField.getPassword())){
					acceso=true;
				}
			}
			if(acceso){
				p.setVisible(true);
				frmFisiosoft.dispose();
			}else{
				JOptionPane.showMessageDialog(btnNewButton, "Usuario o Password incorrecto", "Acceso Denegado", JOptionPane.ERROR_MESSAGE);
				passwordField.setText("");
				textField.setText("");
			}
		
			
		}
		
	}
}
